<?php

    class filter extends CustomCIUnitTestCase {

        private $items;

        public function __construct() {
            parent::__construct('filter');
        }

        public function setUp() {
            $this->load->config('data/search');
            $this->items = array_std(config_item('search_result'));
        }

        public function tearDown() {
            $this->items = NULL;
        }

        public function testfindUniqueMakeCount() {
            $unique = findUniqueMakeCount($this->items);

            sort_attributes($unique);

            $this->assertEqual(count($unique), 67);
        }

        public function testfindUniquePricesMakeCount() {
            // Kreiramo niz sa jednistvenim atributima
            $unique_price = findUniquePricesMakeCount($this->items);

            $counter = 0;
            foreach ($unique_price as $value):
                $counter+=$value->cnt;
            endforeach;

            $this->assertEqual($unique_price['0,50']->cnt, 1);
            $this->assertEqual($unique_price['50,100']->cnt, 6);
            $this->assertEqual($unique_price['100,150']->cnt, 5);
            $this->assertEqual($unique_price['150,200']->cnt, 2);
            $this->assertEqual($unique_price['200,-1']->cnt, 2);
        }

        public function testJoinGroups() {

            loadJoinedGroupsAttributes($this->items);

            //$this->dump ( $this->items );
        }

        public function testUniqueStars() {
            $unique_star = findUniqueStarsMakeCount($this->items);

            $this->assertEqual($unique_star[4], 4);
            $this->assertEqual($unique_star[3], 3);
            $this->assertEqual($unique_star[5], 1);
            $this->assertEqual($unique_star[2], 1);
        }

        public function testAccType() {
            $items = $this->items;
            filter_acc_type($items, 'hotel');
            $this->assertEqual(count($items), 8);
        }

        public function testFindUniqueAccType() {

            $unique = findUniqueAccType($this->items);

            $this->assertEqual($unique['hotel']->cnt, 8);
            $this->assertEqual($unique['apartment']->cnt, 1);
        }

    }

?>